<?php
define('HOST', 'localhost');
define('USER', 'mes');
define('PASSWORD', '111111');
define('DATABASE', 'mes');
$conn = mysqli_connect(HOST, USER, PASSWORD, DATABASE)or die('数据库连接失败' . mysqli_connect_error());
//$sql = 'select * from liuyan order by id desc';
$sql='select liuyan.id as id,liuyan.content as content,liuyan.time as time,liuyan.username as username,user_info.head as head from liuyan left join user_info on liuyan.username=user_info.name order by liuyan.id desc ';
$res = mysqli_query($conn, $sql);
?>
<!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <style>
            div{width:800px;margin:0 auto;background: #ccc;text-align: left;list-style-type: none;text-decoration: none;}
            img{width:50px;height: 50px;}
        </style>

    </head>
    <body>
        <div>
            <h1>留言板</h1>
            <?php
            session_start();
            if (isset($_SESSION['name'])) {
                $name1 = $_SESSION['name'];
            } else {
                $name1 = '';
            }
            if (!empty($name1)) {
                echo '欢迎' . $name1 . '大爷常来玩啊' . "<a href='zhuxiao.php'>注销</a>";
                ?>
                <form method="post" action="liuyan.php" onsubmit="return check()">
                    <!--<input type="text" name="mes" placeholder="发表获奖感言">-->
                    <!-- 加载编辑器的容器 -->
                    <script id="container" name="mes" type="text/plain"></script>
                    <input type="text" readonly="readonly" name="name" value="<?php echo $name1; ?>" placeholder="用户名">
                    <input type="submit" value="发表">
                </form>
                <?php
            } else {
                echo '<a href="zhuce.php">注册 </a>';
                echo '<a href="denglu.html"> 登录</a>';
            }
            ?>          
        </div>
        <div><ul>
                <?php
                while ($row = mysqli_fetch_assoc($res)) {
                    $id = $row['id'];
                    var_dump($id);
                    $username = $row['username'];
                    $time = $row['time'];
                    $content = $row['content'];
                    $head=$row['head'];
                    if (!$username) {
                        $username = '匿名用户';
                    }
                    $time = date('Y-m-d H:i:s', $time);
                    ?>
                <li> 
                    <img src="<?php echo $head;?>" alt=""/>
                        <p style="display: inline-block;"><?php echo $username ?> 在<?php echo $time ?>时说</p>
                        <p><?php echo $content ?></p>
                        <?php
                        if ($username === $name1) {
                            ?>
                            <a href="delete.php?id=<?php echo $id ?>">删除</a>;
                            <a href="xiugai.php?id=<?php echo $id ?>">修改</a>;
                            <?php
                        } else {
                            
                        }
                        ?>      

                    </li>

                <?php } ?>
            </ul>

        </div>
        <script src="liuyan0.js" type="text/javascript"></script>
        <script type="text/javascript" src="ueditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="ueditor/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
    <script type="text/javascript">
                var ue = UE.getEditor("container");
    </script>
    </body>

</html>
